package com.aizhixin.lab.project.template.service;

import com.aizhixin.lab.common.core.DataValidity;
import com.aizhixin.lab.post.entity.Post;
import com.aizhixin.lab.post.repository.PostRepository;
import com.aizhixin.lab.project.template.domain.ProjectRoleDomain;
import com.aizhixin.lab.project.template.entity.Project;
import com.aizhixin.lab.project.template.entity.ProjectRole;
import com.aizhixin.lab.project.template.repository.ProjectRoleRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.swing.plaf.basic.BasicEditorPaneUI;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Slf4j
@Service
@Transactional
public class ProjectRoleService {
    @Autowired
    private ProjectRoleRepository roleRepository;
    @Autowired
    private PostRepository postRepository;
    public ProjectRole save(ProjectRole domain) {
        if (null == domain.getId() || "".equals(domain.getId())) {
            domain.setId(UUID.randomUUID().toString());
        }
        return roleRepository.save(domain);
    }
    public String save(ProjectRoleDomain domain) {
        if (null == domain.getId() || "".equals(domain.getId())) {
            domain.setId(UUID.randomUUID().toString());
        }
        ProjectRole projectRole = new ProjectRole();
        BeanUtils.copyProperties(domain,projectRole);
        roleRepository.save(projectRole);
        return  "OK";
    }
    public List<ProjectRoleDomain> findRoleList(){
        List<ProjectRole> all = roleRepository.findAll();
        List<ProjectRoleDomain> domains=new ArrayList<>();
        for (ProjectRole role:all){
            ProjectRoleDomain roleDomain = new ProjectRoleDomain();
            BeanUtils.copyProperties(role,roleDomain);
            domains.add(roleDomain);
        }
        return domains;
    }
    public void delete(String id){
         roleRepository.delete(id);
    }
//    public void syncRole(){
//        List<Post> postList = postRepository.findByDeleteFlag(DataValidity.VALID.getState());
//
//
//
//    }

}
